# 读取文件,解析文件,获取每个人最快的3个时间段
# 函数处理字符串的问题
def sanitize(time_string):
    if '-' in time_string:
        splitter = '-'
    elif ':' in time_string:
        splitter = ':'
    else:
        return time_string
    (mins, secs) = time_string.split(splitter)
    return mins+'.'+secs

def openFun(file):
    try:
        with open(file) as f:
            data = f.readline()
        return data.strip().split(',')
    except IOError as perr:
        print('FileError:'+ str(perr))
        return (None)

james = openFun('james.txt')
julie = openFun('julie.txt')
# with open('james.txt') as jaf:
#     data = jaf.readline()
# james = data.strip().split(',')

# with open('julie.txt') as juf:
#     data = juf.readline()
# julie = data.strip().split(',')

# with open('mikey.txt') as mif:
#     data = mif.readline()
# mikey = data.strip().split(',')

# with open('sarah.txt') as saf:
#     data = saf.readline()
# sarah = data.strip().split(',')

# cleanJames=[]
# cleanJulie=[]
# cleanMikey=[]
# cleanSarah=[]

# for ev_item in james:
#     cleanJames.append(sanitize(ev_item))
# for ev_item in julie:
#     cleanJulie.append(sanitize(ev_item))
# for ev_item in mikey:
#     cleanMikey.append(sanitize(ev_item))
# for ev_item in sarah:
#     cleanSarah.append(sanitize(ev_item))    

# print(sorted(cleanJames))
# print(sorted(cleanJulie))
# print(sorted(cleanMikey))
# print(sorted(cleanSarah))

# 列表推导
james = (sorted([sanitize(ev_item) for ev_item in james]))
# julie=(sorted([sanitize(ev_item) for ev_item in julie]))
# mikey = (sorted([sanitize(ev_item) for ev_item in mikey]))
# sarah =(sorted([sanitize(ev_item) for ev_item in sarah]))

# 过滤重复数据
unique_james= []
for ev_item in james:
    if not ev_item in unique_james:
        unique_james.append(ev_item)
print(unique_james[0:3])
print(sorted(set([sanitize(ev_item) for ev_item in julie]))[0:3])